package gui.tableCellRenderers;

import java.awt.Color;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;
import ukoly.ProjektControl;
import uzivatele.Uzivatel;

/**
 * Prevzato ze Sunovskyho tutorialu, s upravama
 * @author Pavel Lieberzeit
 */
public class VlastnikCellRenderer  extends JLabel
                           implements TableCellRenderer {
    Border unselectedBorder = null;
    Border selectedBorder = null;
    boolean isBordered = true;

    public VlastnikCellRenderer(boolean isBordered) {
        this.isBordered = isBordered;
        setOpaque(true); //MUST do this for background to show up.
    }

    public Component getTableCellRendererComponent(
                            JTable table, Object vlastnik,
                            boolean isSelected, boolean hasFocus,
                            int row, int column) {
        //TODO vyrob nejaky pouzitelny bordery jestli bude cas
//        if (isBordered) {
//            if (isSelected) {
//                if (selectedBorder == null) {
//                    selectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
//                                              table.getSelectionBackground());
////                    selectedBorder = BorderFactory.createLineBorder(table.getSelectionBackground());
//                    setBackground(table.getSelectionBackground());
//                    setForeground(table.getSelectionForeground());
//                }
//                setBorder(selectedBorder);
//            } else {
//                if (unselectedBorder == null) {
//                    unselectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
//                                              table.getBackground());
////                    unselectedBorder = BorderFactory.createLineBorder(table.getBackground());
//                    setBackground(table.getBackground());
//                    setForeground(table.getForeground());
//                }
//                setBorder(unselectedBorder);
//            }
//        }
        
        if(isSelected) {
            setBackground(table.getSelectionBackground());
            setForeground(table.getSelectionForeground());
        } else {
            setBackground(table.getBackground());
            setForeground(table.getForeground());
        }
        
        if((Uzivatel) vlastnik == null) {
            this.setText("-");
        } else {
            this.setText(((Uzivatel)vlastnik).getJmeno() +" "+ ((Uzivatel)vlastnik).getPrijmeni());
            this.setToolTipText(((Uzivatel)vlastnik).getJmeno() +" "+ ((Uzivatel)vlastnik).getPrijmeni());
        }
        
        return this;
    }
}